<template>
  <!-- 深化设计成果管理 -->
  <base-breadcrumb class="flexMemberInfo-container">
    <!-- 搜索 -->
    <searchData
            :search-data="searchOption"
            @search="search"
    />
    <!-- 搜索 -->
    <a-card>
      <div class="table-operator">
        <!-- <title-name title="深化设计成果列表" /> -->
      </div>
      <!-- 表格操作 -->
      <list-table
              ref="table"
              :page-keys="['pageNum', 'pageSize', 'total']"
              :columns="columns"
              :request="loadData"
              :exportConfig="{ use: true,select: '深化设计成果管理',all: '深化设计成果管理'}"
              :statisticsConfig="{use: true,statistics,temp}"
      >
        <template slot="operation" slot-scope="text,record">
          <MoreButton>
          <span>
            <a @click="handleDetail(record, 0)">查看</a>
          </span>
          <span v-if="(record.resultsStatus === 0 || record.resultsStatus === 3)&&hideBuquBtn()">
            <a @click="handleOperation(record, 1)">编辑</a>
          </span>
          <span v-if="record.resultsStatus === 0&&hideBuquBtn()">
            <a @click="handleDelete(record)">删除</a>
          </span>
          <span v-if="record.resultsStatus !== 0">
            <a @click="handleApprova(record)">审核信息</a>
          </span>
          </MoreButton>
        </template>
        <template slot="prefix">
          <a-button
                  type="primary"
                  icon="plus"
                  v-if="hideBuquBtn()"
                  @click="handleOperation(null, 2)">新增深化设计成果</a-button>
        </template>
      </list-table>
      <!-- 表格操作 -->
    </a-card>
      <!-- 审批详情 -->
      <ApprovalDetails
              :title="'审批详情'"
              :business-id="businessId"
              :visible="visibleApprove"
              @cancel="visibleApprove = false"
              @confirm="visibleApprove = false"
      />
  </base-breadcrumb>
  <!-- 深化设计成果管理 -->
</template>
<script>
  import { searchOption, columns } from './model.js'
  import {getList, findListCount, getDelete} from '@/api/design/deepDesign/outcomeManagement'
  import ApprovalDetails from '@/components/approvalDetails'
  export default {
    name: 'outcomeManagement',
    components: {
      ApprovalDetails
    },
    data() {
      return {
        //审批信息
        businessId:"",
        visibleApprove: false,
        // 搜索选项
        searchOption,
        // 表头
        columns,
        // 查询参数
        searchData: {},
        // 统计
        statistics: {
          draft:0,
          submitted:0,
          past:0,
          rejected:0,
        },
        temp: () => {
          return (
            <span style="margin-right: 12px">
            待提交审核：{this.statistics.draft}&nbsp;&nbsp;
            审核中：{this.statistics.submitted}&nbsp;&nbsp;
            审核通过：{this.statistics.past}&nbsp;&nbsp;
            审核不通过：{this.statistics.rejected}
          </span>
        )},
        // 表数据加载
        loadData: (parameter) => {
          const requestParameters = Object.assign({}, parameter, { param: this.searchData })
          findListCount({},requestParameters).then(res => {
            let data =res.data
            if (res.code === 200)
              this.statistics ={
                draft: data?.draftNum || 0,
                submitted: data?.submittedNum || 0,
                past: data?.pastNum || 0,
                rejected: data?.rejectedNum || 0,
              }
          })
          return getList({},requestParameters).then(res => {
            if (res.code === 200) {
              return { code: 200, data: res.data.list, ...res.data }
            }
          })
        }
      }
    },
    created() {
      // this.getDesignType()
    },
    methods: {
      /**
       * @description: 项目设计管理类别
       * @param {void}
       * @return {void}
       */
      // async getDesignType() {
        // const { data } = await planningManagement.getDesignType({ type: 9 })
        // this.searchOption[5].data = this.getChangeDatatTypes(data) || []
      // },
      /**
       * @description: 搜索
       * @param {Object} value 搜索数据
       * @return {Void}
       */
      search(value) {
        this.searchData = value || {}
        this.$refs.table.getData(null, true)
      },
      /**
       * @description: 新增编辑
       * @param {object} record 行数据
       * @param {string} editModel 页面类型
       * @return {void}
       */
      handleOperation(record, editModel) {
        let id = editModel != 2 ? record.id : ''
        this.$router.push({
          path: `/project/design/deepDesign/outcomeManagement/form`,
          query: {
            id: id,
            editModel:editModel
          }
        })
      },
      /**
       * @description: 查看
       * @param {object} record 行数据
       * @param {string} editModel 页面类型
       * @return {void}
       */
      handleDetail(record, editModel) {
        this.$router.push({
          path: `/project/design/deepDesign/outcomeManagement/detailForm`,
          query: {
            id: record.id
          }
        })
      },
      /**
       * 删除
       **/
      handleDelete(record){
        const vm = this
          vm.$confirm({
            title: '温馨提示',
            content: `确认删除？`,
            okText: '确认',
            okType: 'danger',
            cancelText: '取消',
            async onOk() {
              getDelete({ id: record.id }).then(({ code, message }) => {
                if (code === 200) {
                  vm.$message.success('删除成功')
                  vm.$refs.table.getData(null, true)
                } else {
                  vm.$message.warning(message)
                }
              })
            }
          })
      },
      /**
       * @description: 审批详情
       * @param {Object} record 行数据
       * @return {Void}
       */
      handleApprova(e){
          // this.$bus.$emit('showApprovalDetailsDialog', record.id)
        if(e.id){
          this.visibleApprove= true;
          this.businessId = e.id;
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
